package com.shixi.shixitraining.shixitraining.ui.tabmine.fragment;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.shixi.shixitraining.shixitraining.R;
import com.shixi.shixitraining.shixitraining.base.TabhostBaseFragment;
import com.shixi.shixitraining.shixitraining.http.CallbackImple;
import com.shixi.shixitraining.shixitraining.http.HttpUtil;
import com.shixi.shixitraining.shixitraining.ui.tabmine.adapter.JobPayAdapter;
import com.shixi.shixitraining.shixitraining.ui.tabmine.entity.JobPayBean;
import com.shixi.shixitraining.shixitraining.util.ToastUtil;
import com.shixi.shixitraining.shixitraining.util.UserManager;

import java.util.List;

import retrofit2.Call;

import static com.shixi.shixitraining.shixitraining.constant.Constants.PAY;

/**
 * Created by shenyan on 2018/7/26.
 */

public class PayEmploymentFragment extends TabhostBaseFragment {


    private TextView mNoPay;

    @Override
    protected int getlayoutId() {
        return R.layout.fragment_pay_employment;
    }

    @Override
    protected void initPager() {

//
//        List<TestPayBean>  data=new ArrayList<>();
//        data.add(new TestPayBean("美国金融实习岗位-信托和过桥基金业务","2018.03.03","$600.00"));
//        data.add(new TestPayBean("美国金融实习岗位-信托和过桥基金业务","2018.03.03","$600.00"));
//        data.add(new TestPayBean("美国金融实习岗位-信托和过桥基金业务","2018.03.03","$600.00"));
//        data.add(new TestPayBean("美国金融实习岗位-信托和过桥基金业务","2018.03.03","$600.00"));
//        data.add(new TestPayBean("美国金融实习岗位-信托和过桥基金业务","2018.03.03","$600.00"));
//        data.add(new TestPayBean("美国金融实习岗位-信托和过桥基金业务","2018.03.03","$600.00"));
//        data.add(new TestPayBean("美国金融实习岗位-信托和过桥基金业务","2018.03.03","$600.00"));
//        data.add(new TestPayBean("美国金融实习岗位-信托和过桥基金业务","2018.03.03","$600.00"));
        mNoPay = (TextView) mContentView.findViewById(R.id.tv_nopay);
        String token = UserManager.getInstance().getToken();
        String userId = UserManager.getInstance().getUserId();

        requestJobPay(token,userId);

    }

    private void requestJobPay(String token, String userId) {

        String url=PAY+"?&token="+token+"&userId="+userId+"&iscate="+0;

        HttpUtil.getInstance().getApiInterface().jobPay(url).enqueue(new CallbackImple<JobPayBean>() {
            @Override
            public void onError(Call<JobPayBean> call, Throwable t) {
                ToastUtil.showShortToast(getContext(),t.getMessage());
            }

            @Override
            public void onSuccess(Call<JobPayBean> call, JobPayBean response) {
                if (response.getStatus()==200){
                    if (response.getData()!=null){
                        List<JobPayBean.DataBean> data = response.getData();
                        RecyclerView mRcView = (RecyclerView) mContentView.findViewById(R.id.rcview_pay_employment);
                        LinearLayoutManager manager=new LinearLayoutManager(getContext());
                        manager.setOrientation(LinearLayoutManager.VERTICAL);
                        mRcView.setLayoutManager(manager);

                        JobPayAdapter adapter=new JobPayAdapter(getContext(),data);
                        mRcView.setAdapter(adapter);

                    }else {
                        ToastUtil.showShortToast(getContext(),"数据为空");
                    }
                }else {
                    mNoPay.setVisibility(View.VISIBLE);
                    ToastUtil.showShortToast(getContext(),"数据加载失败");
                }

            }
        });


    }
}
